home *** CD-ROM | disk | FTP | other *** search
/ Total Web Page (Professional Suite) / Total Web Page 99.iso / CGI / DOWNLOAD.CGI-S=WWWBOARD&C=TXT&F=WWWADMIN.PL < prev    next >
Perl Script  |  1996-06-03  |  27KB  |  676 lines

  1. #!/usr/local/bin/perl
  2. ##############################################################################
  3. # WWWBoard Admin                Version 2.0 ALPHA 2                          #
  4. # Copyright 1996 Matt Wright    mattw@worldwidemart.com                      #
  5. # Created 10/21/95              Last Modified 11/25/95                       #
  6. # Scripts Archive at:           http://www.worldwidemart.com/scripts/        #
  7. ##############################################################################
  8. # COPYRIGHT NOTICE                                                           #
  9. # Copyright 1996 Matthew M. Wright  All Rights Reserved.                     #
  10. #                                                                            #
  11. # WWWBoard may be used and modified free of charge by anyone so long as      #
  12. # this copyright notice and the comments above remain intact.  By using this #
  13. # code you agree to indemnify Matthew M. Wright from any liability that      #  
  14. # might arise from it's use.                                                 #  
  15. #                                                                            #
  16. # Selling the code for this program without prior written consent is         #
  17. # expressly forbidden.  In other words, please ask first before you try and  #
  18. # make money off of my program.                                              #
  19. #                                                                            #
  20. # Obtain permission before redistributing this software over the Internet or #
  21. # in any other medium.  In all cases copyright and header must remain intact.#
  22. ###########################################################################
  23. # Define Variables
  24.  
  25. $basedir = "/path/to/wwwboard";
  26. $baseurl = "http://your.host.xxx/wwwboard";
  27. $cgi_url = "http://your.host.xxx/cgi-bin/wwwadmin.pl";
  28.  
  29. $mesgdir = "messages";
  30. $datafile = "data.txt";
  31. $mesgfile = "wwwboard.html";
  32. $passwd_file = "passwd.txt";
  33.  
  34. $ext = "html";
  35.  
  36. $title = "WWWBoard Version 2.0 Test";
  37. $use_time = 1;        # 1 = YES; 0 = NO
  38.  
  39. # Done
  40. ###########################################################################
  41.  
  42. if ($ENV{'QUERY_STRING'} ne '') {
  43.    $command = "$ENV{'QUERY_STRING'}";
  44. }
  45. else {
  46.    &parse_form;
  47. }
  48.  
  49. print "Content-type: text/html\n\n";
  50.  
  51. ###########################################################################
  52. # Remove                                                                  #
  53. #       This option is useful to see how the threads appear in the        #
  54. #   wwwboard.html document.  It can give you a better idea of whether or  #
  55. #   not you want to remove the whole thread or just part of it.           #
  56. ###########################################################################
  57.  
  58. if ($command eq 'remove') {
  59.    print "<html><head><title>Remove Messages From WWWBoard</title></head>\n";
  60.    print "<body><center><h1>Remove Messages From WWWBoard</h1></center>\n";
  61.    print "Select below to remove those postings you wish to remove.\n";
  62.    print "Checking the Input Box on the left will remove the whole thread\n";
  63.    print "while checking the Input Box on the right to remove just that posting.<p>\n";
  64.    print "These messages have been left unsorted, so that you can see the order in\n";
  65.    print "which they appear in the $mesgpage page.  This will give you an idea oF\n";
  66.    print "what the threads look like and is often more helpful than the sorted method.\n";
  67.    print "<p>\n";
  68.    print "<hr size=7 width=75%><center><font size=-1>\n";
  69.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a hre
  70. f=\"$baseurl/$mesgpage\">$title</a> ]\n";
  71.    print "</font></center><hr size=7 width=75%><p>\n";
  72.    print "<form method=POST action=\"$cgi_url\">\n";
  73.    print "<input type=hidden name=\"action\" value=\"remove\">\n";
  74.    print "<table border>\n";
  75.    print "<tr>\n";
  76.    print "<th colspan=6>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"></th>\n";
  77.    print "</tr><tr>\n";
  78.    print "<th>Post # </th><th>Thread </th><th>Single </th><th>Subject </th><th> Author</th><th> Date</th></tr>\n";
  79.  
  80.    open(MSGS,"$basedir/$mesgfile");
  81.    @lines = <MSGS>;
  82.    close(MSGS);
  83.  
  84.    foreach $line (@lines) {
  85.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">(.*)<\/a> - <b>(.*)<\/b>\s+<i>(.*)<\/i>/) {
  86.          push(@ENTRIES,$1);
  87.          $SUBJECT{$1} = $2;
  88.          $AUTHOR{$1} = $3;
  89.          $DATE{$1} = $4;
  90.       }
  91.    }
  92.  
  93.    @SORTED_ENTRIES = (sort { $a <=> $b } @ENTRIES);
  94.    $max = pop(@SORTED_ENTRIES);
  95.    $min = shift(@SORTED_ENTRIES);
  96.  
  97.    print "<input type=hidden name=\"min\" value=\"$min\">\n";
  98.    print "<input type=hidden name=\"max\" value=\"$max\">\n";
  99.    print "<input type=hidden name=\"type\" value=\"remove\">\n";
  100.  
  101.    foreach (@ENTRIES) {
  102.       print "<tr>\n";
  103.       print "<th><b>$_</b> </th><td><input type=radio name=\"$_\" value=\"all\"> </td><td><input type=radio name=\"$_\" value=\"single\"> </td><td><a href=\"$baseurl/$mesgdir/$_\.$ext\">$SUBJECT{$_} </a></td><td>$AUTHOR{$_} </td><td>$DATE{$_}<br></td>\n";
  104.  
  105.       print "</tr>\n";
  106.    }
  107.    print "</table>\n";
  108.    print "<center><p>\n";
  109.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  110.    print "</form>\n";
  111.    print "</body></html>\n";
  112. }
  113.  
  114. ###########################################################################
  115. # Remove By Number                                                        #
  116. #       This method is useful to see in what order the messages were      #
  117. #   added to the wwwboard.html document.                                  #
  118. ###########################################################################
  119.  
  120. elsif ($command eq 'remove_by_num') {
  121.    print "<html><head><title>Remove Messages From WWWBoard By Number</title></head>\n";
  122.    print "<body><center><h1>Remove Messages From WWWBoard By Number</h1></center>\n";
  123.    print "Select below to remove those postings you wish to remove.\n";
  124.    print "Checking the Input Box on the left will remove the whole thread\n";
  125.    print "while checking the Input Box on the right to remove just that posting.\n";
  126.    print "<p>\n";
  127.    print "<hr size=7 width=75%><center><font size=-1>\n";
  128.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a hre
  129. f=\"$baseurl/$mesgpage\">$title</a> ]\n";
  130.    print "</font></center><hr size=7 width=75%><p>\n";
  131.    print "<form method=POST action=\"$cgi_url\">\n";
  132.    print "<input type=hidden name=\"action\" value=\"remove\">\n";
  133.    print "<table border>\n";
  134.    print "<tr>\n";
  135.    print "<th colspan=6>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"><br></th>\n";
  136.    print "</tr>\n";
  137.    print "<tr>\n";
  138.    print "<th>Post # </th><th>Thread </th><th>Single </th><th>Subject </th><th> Author</th><th> Date</th></tr>\n";
  139.  
  140.    open(MSGS,"$basedir/$mesgfile");
  141.    @lines = <MSGS>;
  142.    close(MSGS);
  143.  
  144.    foreach $line (@lines) {
  145.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">(.*)<\/a> - <b>(.*)<\/b>\s+<i>(.*)<\/i>/) {
  146.          push(@ENTRIES,$1);
  147.          $SUBJECT{$1} = $2;
  148.          $AUTHOR{$1} = $3;
  149.          $DATE{$1} = $4;
  150.       }
  151.    }
  152.  
  153.    @SORTED_ENTRIES = (sort { $a <=> $b } @ENTRIES);
  154.    $max = pop(@SORTED_ENTRIES);
  155.    $min = shift(@SORTED_ENTRIES);
  156.    push(@SORTED_ENTRIES,$max);
  157.    unshift(@SORTED_ENTRIES,$min);
  158.  
  159.    print "<input type=hidden name=\"min\" value=\"$min\">\n";
  160.    print "<input type=hidden name=\"max\" value=\"$max\">\n";
  161.    print "<input type=hidden name=\"type\" value=\"remove\">\n";
  162.  
  163.    foreach (@SORTED_ENTRIES) {
  164.       print "<tr>\n";
  165.       print "<th><b>$_</b> </th><td><input type=radio name=\"$_\" value=\"all\"> </td><td><input type=radio name=\"$_\" value=\"single\"> </td><td><a href=\"$baseurl/$mesgdir/$_\.$ext\">$SUBJECT{$_} </a></td><td>$AUTHOR{$_} </td><td>$DATE{$_}<br></td>\n";
  166.  
  167.       print "</tr>\n";
  168.    }
  169.    print "</table>\n";
  170.    print "<center><p>\n";
  171.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  172.    print "</form>\n";
  173.    print "</body></html>\n";
  174. }
  175.  
  176. ###########################################################################
  177. # Remove By Date                                                          #
  178. #       Using this method allows you to delete all messages posted before #
  179. #   a certain date.                                                       #
  180. ###########################################################################
  181.  
  182. elsif ($command eq 'remove_by_date') {
  183.    print "<html><head><title>Remove Messages From WWWBoard By Date</title></head>\n";
  184.    print "<body><center><h1>Remove Messages From WWWBoard By Date</h1></center>\n";
  185.    print "Select below to remove those postings you wish to remove.\n";
  186.    print "Checking the input box beside a date will remove all postings \n";
  187.    print "that occurred on that date.\n";
  188.    print "<p>\n";
  189.    print "<hr size=7 width=75%><center><font size=-1>\n";
  190.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a hre
  191. f=\"$baseurl/$mesgpage\">$title</a> ]\n";
  192.    print "</font></center><hr size=7 width=75%>\n";
  193.    print "<p>\n";
  194.    print "<form method=POST action=\"$cgi_url\">\n";
  195.    print "<input type=hidden name=\"action\" value=\"remove_by_date_or_author\">\n";
  196.    print "<input type=hidden name=\"type\" value=\"remove_by_date\">\n";
  197.    print "<center>\n";
  198.    print "<table border>\n";
  199.    print "<tr>\n";
  200.    print "<th colspan=4>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"><br></th>\n";
  201.    print "</tr>\n";
  202.    print "<tr>\n";
  203.    print "<th>X </th><th>Date </th><th># of Messages </th><th>Message Numbers<br></th></tr>\n";
  204.  
  205.    open(MSGS,"$basedir/$mesgfile");
  206.    @lines = <MSGS>;
  207.    close(MSGS);
  208.  
  209.    foreach $line (@lines) {
  210.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">.*<\/a> - <b>.*<\/b>\s+<i>(.*)<\/i>/) {
  211.          $date = $2;
  212.          if ($use_time == 1) {
  213.             ($time,$day) = split(/\s+/,$date);
  214.          }
  215.          else {
  216.             $day = $date;
  217.          }
  218.          $DATE{$1} = $day;
  219.       }
  220.    }
  221.  
  222.    undef(@used_values);
  223.    foreach $value (sort (values %DATE)) {
  224.       $match = '0';
  225.       $value_number = 0;
  226.       foreach $used_value (@used_values) {
  227.          if ($value eq $used_value) {
  228.             $match = '1';
  229.             last;
  230.          }
  231.       }
  232.       if ($match == '0') {
  233.          undef(@values); undef(@short_values);
  234.          foreach $key (keys %DATE) {
  235.             if ($value eq $DATE{$key}) {
  236.                $key_url = "<a href=\"$baseurl/$mesgdir/$key\.$ext\">$key</a>";
  237.                push(@values,$key_url);
  238.            push(@short_values,$key);
  239.                $value_number++;
  240.             }
  241.          }
  242.          $form_value = $value;
  243.          $form_value =~ s/\//_/g;
  244.          print "<tr>\n";
  245.          print "<td><input type=checkbox name=\"$form_value\" value=\"@short_values\"> </td><th>$value </th><td>$value_number </td><td>@values<br></td>\n";
  246.          print "</tr>\n";
  247.          push(@used_values,$value);
  248.          push(@used_form_values,$form_value);
  249.       }
  250.    }
  251.    print "</table><p>\n";
  252.    print "<input type=hidden name=\"used_values\" value=\"@used_form_values\">\n";
  253.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  254.    print "</form></center>\n";
  255.    print "</body></html>\n";
  256. }
  257.  
  258. ###########################################################################
  259. # Remove By Author                                                        #
  260. #       This option makes a list of all known authors and then groups     #
  261. #    together there postings and allows you to remove them all at once.   #
  262. ###########################################################################
  263.  
  264. elsif ($command eq 'remove_by_author') {
  265.    print "<html><head><title>Remove Messages From WWWBoard By Author</title></head>\n";
  266.    print "<body><center><h1>Remove Messages From WWWBoard By Author</h1></center>\n";
  267.    print "Checking the checkbox beside the name of an author will remove \n";
  268.    print "all postings which that author has created.\n";
  269.    print "<p>\n";
  270.    print "<hr size=7 width=75%><center><font size=-1>\n";
  271.    print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a hre
  272. f=\"$baseurl/$mesgpage\">$title</a> ]\n";
  273.    print "</font></center><hr size=7 width=75%>\n";
  274.    print "<p>\n";
  275.    print "<form method=POST action=\"$cgi_url\">\n";
  276.    print "<input type=hidden name=\"action\" value=\"remove_by_date_or_author\">\n";
  277.    print "<input type=hidden name=\"type\" value=\"remove_by_author\">\n";
  278.    print "<center>\n";
  279.    print "<table border>\n";
  280.    print "<tr>\n";
  281.    print "<th colspan=4>Username: <input type=text name=\"username\"> -- Password: <input type=password name=\"password\"><br></th>\n";
  282.    print "</tr>\n";
  283.    print "<tr>\n";
  284.    print "<th>X </th><th>Author </th><th># of Messages </th><th>Message #'s<br></th></tr>\n";
  285.  
  286.    open(MSGS,"$basedir/$mesgfile");
  287.    @lines = <MSGS>;
  288.    close(MSGS);
  289.  
  290.    foreach $line (@lines) {
  291.       if ($line =~ /<!--top: (.*)--><li><a href="$mesgdir\/\1\.$ext">.*<\/a> - <b>(.*)<\/b>\s+<i>.*<\/i>/) {
  292.          $AUTHOR{$1} = $2;
  293.       }
  294.    }
  295.  
  296.    undef(@used_values);
  297.    foreach $value (sort (values %AUTHOR)) {
  298.       $match = '0';
  299.       $value_number = 0;
  300.       foreach $used_value (@used_values) {
  301.          if ($value eq $used_value) {
  302.             $match = '1';
  303.             last;
  304.          }
  305.       }
  306.       if ($match == '0') {
  307.          undef(@values); undef(@short_values);
  308.          foreach $key (keys %AUTHOR) {
  309.             if ($value eq $AUTHOR{$key}) {
  310.                $key_url = "<a href=\"$baseurl/$mesgdir/$key\.$ext\">$key</a>";
  311.                push(@values,$key_url);
  312.                push(@short_values,$key);
  313.                $value_number++;
  314.             }
  315.          }
  316.          $form_value = $value;
  317.          $form_value =~ s/ /_/g;
  318.          print "<tr>\n";
  319.          print "<td><input type=checkbox name=\"$form_value\" value=\"@short_values\"> </td><th align=left>$value </th><td>$value_number </td><td>@values<br></td>\n";
  320.          print "</tr>\n";
  321.          push(@used_values,$value);
  322.          push(@used_form_values,$form_value);
  323.       }
  324.    }
  325.    print "</table><p>\n";
  326.    print "<input type=hidden name=\"used_values\" value=\"@used_form_values\">\n";
  327.    print "<input type=submit value=\"Remove Messages\"> <input type=reset>\n";
  328.    print "</form></center>\n";
  329.    print "</body></html>\n";
  330.  
  331. }
  332.  
  333. ###########################################################################
  334. # Change Password                                                         #
  335. #       By calling this section of the script, the admin can change his or#
  336. #   her password.                              #
  337. ###########################################################################
  338.  
  339. elsif ($command eq 'change_passwd') {
  340.  
  341.    print "<html><head><title>Change WWWBoard Admin Password</title></head>\n";
  342.    print "<body><center><h1>Change WWWBoard Admin Password</h1></center>\n";
  343.    print "Fill out the form below completely to change your password and user name.\n";
  344.    print "If new username is left blank, your old one will be assumed.<p><hr size=7 width=75%><p>\n";
  345.    print "<form method=POST action=\"$cgi_url\">\n";
  346.    print "<input type=hidden name=\"action\" value=\"change_passwd\">\n";
  347.    print "<center><table border=0>\n";
  348.    print "<tr>\n";
  349.    print "<th align=left>Username: </th><td><input type=text name=\"username\"><br></td>\n";
  350.    print "</tr><tr>\n";
  351.    print "<th align=left>Password: </th><td><input type=password name=\"password\"><br></td>\n";
  352.    print "</tr><tr> </tr><tr>\n";
  353.    print "<th align=left>New Username: </th><td><input type=text name=\"new_username\"><br></td>\n";
  354.    print "</tr><tr>\n";
  355.    print "<th align=left>New Password: </th><td><input type=password name=\"passwd_1\"><br></td>\n";
  356.    print "</tr><tr>\n";
  357.    print "<th align=left>Re-type New Password: </th><td><input type=password name=\"passwd_2\"><br></td>\n";
  358.    print "</tr><tr>\n";
  359.    print "<td align=center><input type=submit value=\"Change Password\"> </td><td align=center><input type=reset></td>\n";
  360.    print "</tr></table></center>\n";
  361.    print "</form></body></html>\n";
  362.  
  363. }
  364.  
  365. ###########################################################################
  366. # Remove Action                                                           #
  367. #       This portion is used by the options remove and remove_by_num.     #
  368. ###########################################################################
  369.  
  370. elsif ($FORM{'action'} eq 'remove') {
  371.  
  372.    &check_passwd;
  373.  
  374.    for ($i = $FORM{'min'}; $i <= $FORM{'max'}; $i++) {
  375.       if ($FORM{$i} eq 'all') {
  376.          push(@ALL,$i);
  377.       }
  378.       elsif ($FORM{$i} eq 'single') {
  379.          push(@SINGLE,$i);
  380.       }
  381.    }
  382.  
  383.    open(MSGS,"$basedir/$mesgfile");
  384.    @lines = <MSGS>;
  385.    close(MSGS);
  386.  
  387.    foreach $single (@SINGLE) {
  388.       foreach ($j = 0;$j <= @lines;$j++) {
  389.          if ($lines[$j] =~ /<!--top: $single-->/) {
  390.             splice(@lines, $j, 3);
  391.             $j -= 3;
  392.          }
  393.          elsif ($lines[$j] =~ /<!--end: $single-->/) {
  394.             splice(@lines, $j, 1);
  395.             $j--;
  396.          }
  397.       }
  398.       $filename = "$basedir/$mesgdir/$single\.$ext";
  399.       if (-e $filename) {
  400.          unlink("$filename") || push(@NOT_REMOVED,$single);
  401.       }
  402.       else {
  403.          push(@NO_FILE,$single);
  404.       }
  405.       push(@ATTEMPTED,$single);
  406.    }
  407.  
  408.    foreach $all (@ALL) {
  409.       undef($top); undef($bottom);
  410.       foreach ($j = 0;$j <= @lines;$j++) {
  411.          if ($lines[$j] =~ /<!--top: $all-->/) {
  412.             $top = $j;
  413.          }
  414.          elsif ($lines[$j] =~ /<!--end: $all-->/) {
  415.             $bottom = $j;
  416.          }
  417.       }
  418.       if ($top && $bottom) {
  419.          $diff = ($bottom - $top);
  420.          $diff++;
  421.          for ($k = $top;$k <= $bottom;$k++) {
  422.             if ($lines[$k] =~ /<!--top: (.*)-->/) {
  423.                push(@DELETE,$1);
  424.             }
  425.          }
  426.          splice(@lines, $top, $diff);
  427.          foreach $delete (@DELETE) {
  428.             $filename = "$basedir/$mesgdir/$delete\.$ext";
  429.             if (-e $filename) {
  430.                unlink($filename) || push(@NOT_REMOVED,$delete);
  431.             }
  432.             else {
  433.                push(@NO_FILE,$delete);
  434.             }
  435.             push(@ATTEMPTED,$delete);
  436.          }
  437.       }
  438.       else {
  439.          push(@TOP_BOT,$all);
  440.       }
  441.    }
  442.  
  443.    open(WWWBOARD,">$basedir/$mesgfile");
  444.    print WWWBOARD @lines;
  445.    close(WWWBOARD);      
  446.  
  447.    &return_html($FORM{'type'});
  448.  
  449. }
  450.  
  451. ###########################################################################
  452. # Remove Action by Date or Author                                         #
  453. #       This portion is used by the method remove_by_date or           #
  454. #   remove_by_author.                                 #
  455. ###########################################################################
  456.  
  457. elsif ($FORM{'action'} eq 'remove_by_date_or_author') {
  458.  
  459.    &check_passwd;
  460.  
  461.    @used_values = split(/\s/,$FORM{'used_values'});
  462.    foreach $used_value (@used_values) {
  463.       @misc_values = split(/\s/,$FORM{$used_value});
  464.       foreach $misc_value (@misc_values) {
  465.          push(@SINGLE,$misc_value);
  466.       }
  467.    }
  468.  
  469.    open(MSGS,"$basedir/$mesgfile");
  470.    @lines = <MSGS>;
  471.    close(MSGS);
  472.  
  473.    foreach $single (@SINGLE) {
  474.       foreach ($j = 0;$j <= @lines;$j++) {
  475.          if ($lines[$j] =~ /<!--top: $single-->/) {
  476.             splice(@lines, $j, 3);
  477.             $j -= 3;
  478.          }
  479.          elsif ($lines[$j] =~ /<!--end: $single-->/) {
  480.             splice(@lines, $j, 1);
  481.             $j--;
  482.          }
  483.       }
  484.       $filename = "$basedir/$mesgdir/$single\.$ext";
  485.       if (-e $filename) {
  486.          unlink("$filename") || push(@NOT_REMOVED,$single);
  487.       }
  488.       else {
  489.          push(@NO_FILE,$single);
  490.       }
  491.       push(@ATTEMPTED,$single);
  492.    }
  493.  
  494.    open(WWWBOARD,">$basedir/$mesgfile");
  495.    print WWWBOARD @lines;
  496.    close(WWWBOARD);
  497.  
  498.    &return_html($FORM{'type'});
  499.  
  500. }
  501.  
  502. elsif ($FORM{'action'} eq 'change_passwd') {
  503.  
  504.    open(PASSWD,"$basedir/$passwd_file") || &error(passwd_file);
  505.    $passwd_line = <PASSWD>;
  506.    chop($passwd_line) if $passwd_line =~ /\n$/;
  507.    close(PASSWD);
  508.  
  509.    ($username,$passwd) = split(/:/,$passwd_line);
  510.  
  511.    if (!($FORM{'passwd_1'} eq $FORM{'passwd_2'})) {
  512.       &error(not_same);
  513.    }
  514.  
  515.    $test_passwd = crypt($FORM{'password'}, substr($passwd, 0, 2));
  516.    if ($test_passwd eq $passwd && $FORM{'username'} eq $username) {
  517.       open(PASSWD,">$basedir/$passwd_file") || &error(no_change);
  518.       $new_password = crypt($FORM{'passwd_1'}, substr($passwd, 0, 2));
  519.       if ($FORM{'new_username'}) {
  520.          $new_username = $FORM{'new_username'};
  521.       }
  522.       else {
  523.          $new_username = $username;
  524.       }
  525.       print PASSWD "$new_username:$new_password";
  526.       close(PASSWD);
  527.    }
  528.    else {
  529.       &error(bad_combo);
  530.    }
  531.  
  532.    &return_html(change_passwd);
  533. }
  534.  
  535. else {
  536.    print "<html><head><title>WWWAdmin For WWWBoard</title></head>\n";
  537.    print "<body bgcolor=#FFFFFF text=#000000><center><h1>WWWAdmin For WWWBoard</h1></center>\n";
  538.    print "Choose your Method of modifying WWWBoard Below:<p>\n";
  539.    print "<hr size=7 width=75%><br>\n";
  540.    print "<ul>\n";
  541.    print "<li>Remove Files\n";
  542.    print "<ul>\n";
  543.    print "<li><a href=\"$cgi_url\?remove\">Remove Files</a>\n";
  544.    print "<li><a href=\"$cgi_url\?removeby_num\">Remove Files by Mesage Number</a>\n";
  545.    print "<li><a href=\"$cgi_url\?remove_by_date\">Remove Files by Date</a>\n";
  546.    print "<li><a href=\"$cgi_url\?remove_by_author\">Remove Files by Author</a>\n";
  547.    print "</ul><br>\n";
  548.    print "<li>Password\n";
  549.    print "<ul>\n";
  550.    print "<li><a href=\"$cgi_url\?change_passwd\">Change Admin Password</a>\n";
  551.    print "</ul>\n";
  552.    print "</ul>\n";
  553. }
  554.  
  555. #######################
  556. # Parse Form Subroutine
  557.  
  558. sub parse_form {
  559.  
  560.    # Get the input
  561.    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  562.  
  563.    # Split the name-value pairs
  564.    @pairs = split(/&/, $buffer);
  565.  
  566.    foreach $pair (@pairs) {
  567.       ($name, $value) = split(/=/, $pair);
  568.  
  569.       # Un-Webify plus signs and %-encoding
  570.       $value =~ tr/+/ /;
  571.       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  572.  
  573.       $FORM{$name} = $value;
  574.    }
  575. }
  576.  
  577. sub return_html {
  578.    $type = $_[0];
  579.    if ($type eq 'remove') {
  580.       print "<html><head><title>Results of Message Board Removal</title></head>\n";
  581.       print "<body><center><h1>Results of Message Board Removal</h1></center>\n";
  582.    }
  583.    elsif ($type eq 'remove_by_num') {
  584.       print "<html><head><title>Results of Message Board Removal by Number</title></head>\n";
  585.       print "<body><center><h1>Results of Message Board Removal by Number</h1></center>\n";
  586.    }
  587.    elsif ($type eq 'remove_by_date') {
  588.       print "<html><head><title>Results of Message Board Removal by Date</title></head>\n";
  589.       print "<body><center><h1>Results of Message Board Removal by Date</h1></center>\n";
  590.    }
  591.    elsif ($type eq 'remove_by_author') {
  592.       print "<html><head><title>Results of Message Board Removal by Author</title></head>\n";
  593.       print "<body><center><h1>Results of Message Board Removal by Author</h1></center>\n";
  594.    }
  595.    elsif ($type eq 'change_passwd') {
  596.       print "<html><head><title>WWWBoard WWWAdmin Password Changed</title></head>\n";
  597.       print "<body><center><h1>WWWBoard WWWAdmin Password Changed</h1></center>\n";
  598.       print "Your Password for WWWBoard WWWAdmin has been changed!  Results are below:<p><hr size=7 width=75%><p>\n";
  599.       print "<b>New Username: $new_username<p>\n";
  600.       print "New Password: $FORM{'passwd_1'}</b><p>\n";
  601.       print "<hr size=7 width=75%><p>\n";
  602.       print "Do not forget these, since they are now encoded in a file, and not readable!.\n";
  603.       print "</body></html>\n";
  604.    }
  605.    if ($type =~ /^remove/) {
  606.       print "Below is a short summary of what messages were removed from $mesgpage and the\n";
  607.       print "$mesgdir directory.  All files that the script attempted to remove, were removed,\n";
  608.       print "unless there is an error message stating otherwise.<p><hr size=7 width=75%><p>\n";
  609.  
  610.       print "<b>Attempted to Remove:</b> @ATTEMPTED<p>\n";
  611.       if (@NOT_REMOVED) {
  612.          print "<b>Files That Could Not Be Deleted:</b> @NOT_REMOVED<p>\n";
  613.       }
  614.       if (@NO_FILE) {
  615.          print "<b>Files Not Found:</b> @NO_FILE<p>\n";
  616.       }
  617.       print "<hr size=7 width=75%><center><font size=-1>\n";
  618.       print "[ <a href=\"$cgi_url\?remove\">Remove</a> ] [ <a href=\"$cgi_url\?remove_by_date\">Remove by Date</a> ] [ <a href=\"$cgi_url\?remove_by_author\">Remove by Author</a> ] [ <a href=\"$cgi_url\?remove_by_num\">Remove by Message Number</a> ] [ <a 
  619. href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  620.       print "</font></center><hr size=7 width=75%>\n";
  621.       print "</body></html>\n";
  622.    }
  623. }
  624.  
  625. sub error {
  626.    $error = $_[0];
  627.    if ($error eq 'bad_combo') {
  628.       print "<html><head><title>Bad Username - Password Combination</title></head>\n";
  629.       print "<body><center><h1>Bad Username - Password Combination</h1></center>\n";
  630.       print "You entered and invalid username password pair.  Please try again.<p>\n";
  631.       &passwd_trailer
  632.    }
  633.    elsif ($error eq 'passwd_file') {
  634.       print "<html><head><title>Could Not Open Password File For Reading</title></head>\n";
  635.       print "<body><center><h1>Could Not Open Password File For Reading</h1></center>\n";
  636.       print "Could not open the password file for reading!  Check permissions and try again.<p>\n";
  637.       &passwd_trailer
  638.    }
  639.    elsif ($error eq 'not_same') {
  640.       print "<html><head><title>Incorrect Password Type-In</title></head>\n";
  641.       print "<body><center><h1>Incorrect Password Type-In</h1></center>\n";
  642.       print "The passwords you typed in for your new password were not the same.\n";
  643.       print "You may have mistyped, please try again.<p>\n";
  644.       &passwd_trailer
  645.    }
  646.    elsif ($error eq 'no_change') {
  647.       print "<html><head><title>Could Not Open Password File For Writing</title></head>\n";
  648.       print "<body><center><h1>Could Not Open Password File For Writing</h1></center>\n";
  649.       print "Could not open the password file for writing!  Password not changed!<p>\n";
  650.       &passwd_trailer
  651.    }
  652.  
  653.    exit;
  654. }
  655.  
  656. sub passwd_trailer {
  657.    print "<hr size=7 width=75%><center><font size=-1>\n";
  658.    print "[ <a href=\"$cgi_url\">WWWAdmin</a> ] [ <a href=\"$baseurl/$mesgpage\">$title</a> ]\n";
  659.    print "</font></center><hr size=7 width=75%>\n";
  660.    print "</body></html>\n";
  661. }
  662.  
  663. sub check_passwd {
  664.    open(PASSWD,"$basedir/$passwd_file") || &error(passwd_file);
  665.    $passwd_line = <PASSWD>;
  666.    chop($passwd_line) if $passwd_line =~ /\n$/;
  667.    close(PASSWD);
  668.  
  669.    ($username,$passwd) = split(/:/,$passwd_line);
  670.  
  671.    $test_passwd = crypt($FORM{'password'}, substr($passwd, 0, 2));
  672.    if (!($test_passwd eq $passwd && $FORM{'username'} eq $username)) {
  673.       &error(bad_combo);
  674.    }
  675. }
  676.